<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => (formState = {})">
      <a-form ref="formRef" class="flex-1" :model="formState" :colon="false" :label-col="{ style: { width: '10px' } }">
        <a-form-item name="keyword" class="w-52">
          <a-input v-model:value="formState.keyword" placeholder="候诊区编号/名称" />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex mb-3">
        <a-button type="primary" @click="addOpenModal()">新增</a-button>
      </div>
      <BaseTable :loading="loading" column-code="000577" row-key="id" fill :data-source="tableData" bordered>
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex === 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'action'">
            <a-button type="link" size="small" @click="onClickDetail(record)"> 修改 </a-button>
            <a-button type="link" size="small" @click="openChildrenScreen(record)"> 子屏 </a-button>
            <a-button type="link" size="small" @click="openQueue(record)">队列</a-button>
            <BaseButton confirm-text="确认删除？" type="link" danger size="small" @click="onClickDel(record)">删除</BaseButton>
          </template>
        </template>
      </BaseTable>
    </a-card>
    <AddModal v-model:open="addOpen" :row-data="rowData" @success="getData()" />
    <Screen v-model:open="screenOpen" :row-data="rowData" @success="getData()" />
    <Queue v-model:open="queueOpen" :row-data="rowData" @success="getData()" />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
import BaseTable from '@/components/BaseTable'
import AddModal from './AddModal.vue'
import Screen from './Screen.vue'
import Queue from './Queue.vue'

const formRef = ref(null)
const formState = ref({
  keyword: ''
})
const addOpen = ref(false)
const screenOpen = ref(false)
const queueOpen = ref(false)
const rowData = ref({})
const onClickDetail = (record) => {
  rowData.value = record
  addOpen.value = true
}
const addOpenModal = () => {
  rowData.value = {}
  addOpen.value = true
}
const openChildrenScreen = (record) => {
  rowData.value = record
  screenOpen.value = true
}
const openQueue = (record) => {
  rowData.value = record
  queueOpen.value = true
}
const { loading, tableData, getData } = useTable({
  url: '/outp/dictRegion/getRegionList',
  params: formState.value,
  pagination: false,
  immediate: true
})
const onClickDel = async (row) => {
  const res = await post('/outp/dictRegion/doDelRegion', { regionId: row.regionId, id: row.id })
  if (res.code !== 0) return message.error(res.msg || '删除失败')
  message.success(res.msg || '删除成功')
  getData()
}
</script>
<style lang="less" scoped>
.ant-picker {
  width: 100%;
}
</style>
